<?php
if($_SESSION['rank'] < 4){
	exit(Lang::getBackGlobal('wrong_permissions'));
}
/**
 * @author Martin Pernica
 * @copyright 2009
 */
 echo "<h2>".Lang::getBackGlobal('log_title')."</h2>\n<br />";
function level($level){
	switch($level){
        case 1:
		    return '<tr class="fatal"><td>Fatal Error</td>';
		break;
		
		case 2:
		    return '<tr class="warning"><td>Warning</td>';
		break;
		
		case 4:
		    return '<tr class="fatal"><td>Parse Error</td>';
		break;
		
		case 8:
		    return '<tr><td>Notice</td>';
		break;
		
		case 10:
		    return '<tr class="warning"><td>Warning</td>';
		break;
		
		case 16:
		    return '<tr class="fatal"><td>PHP Core Fatal Error</td>';
		break;
		
		case 64:
		    return '<tr class="fatal"><td>Zend Scripting Error</td>';
		break;
		
		case 256:
		    return '<tr class="fatal"><td>Fatal Error</td>';
		break;
		
		case 2048:
		    return '<tr class="warning"><td>User-Generated Error</td>';
		break;
		
	}
}

//echo '<p>Stáhnout log (txt)</p>';

$query = Registry::get('db')->query("SELECT * FROM {prefix}log ORDER BY date DESC LIMIT 100");
echo '<table cellspacing="10" class="clean_table">';
echo '<tr><th>'.Lang::getBackGlobal('log_level').'</th><th>'.Lang::getBackGlobal('log_component').'</th><th>'.Lang::getBackGlobal('log_date').'</th><th>'.Lang::getBackGlobal('log_message').'</th><th>'.Lang::getBackGlobal('log_user').'</th><th>'.Lang::getBackGlobal('log_ip').'</th></tr>';
while($data = $query->fetch_array()){
	$user = ($data['user'] == 0) ? 'System' : getUsernameFromDB($data['user']);
	echo level($data['level']).'<td>'.$data['component'].'</td><td>'.$data['date'].'</td><td>'.$data['message'].'</td><td>'.$user.'</td><td>'.$data['ip'].'</td></tr>';
}
echo '</table>';
?>